<?php
/**
 * Created by PhpStorm.
 * User: liyu
 * Date: 2018/4/9
 * Time: 上午9:54
 */

namespace app\common\validate;


use app\common\exception\Base;
use app\common\exception\StatusCode;
use think\Exception;
use think\Request;
use think\Validate;

class BaseValidate extends Validate
{
    public function goCheck($scene = null)
    {
        $data = Request::instance()->param();
        if (!empty($scene)) {
            $row = $this->scene($scene)->batch(true)->check($data);
        } else {
            $row = $this->batch(true)->check($data);
        }

        if ($row) {
            return true;
        } else {
            $e = Base::instance();
            $info = StatusCode::getError('params_error');
            $e->setErrorCode($info['code']);
            $e->setMsg($this->error);
            throw $e;
        }
    }
}